package com.example.meet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.meet.R;
import com.moxun.tagcloudlib.view.TagsAdapter;

import java.util.List;

/**
 * Created By chentao On 2020/7/28 22:45
 * Describe: 3D星球适配器
 */
public class CloudTagAdapter extends TagsAdapter {

    private Context context;
    private List<String> mList;
    private LayoutInflater inflater;

    public CloudTagAdapter(Context context, List<String> mList) {
        this.context = context;
        this.mList = mList;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    protected void setOnDataSetChangeListener(OnDataSetChangeListener listener) {
        super.setOnDataSetChangeListener(listener);
    }

    /**
     * 返回tag数量
     * @return
     */
    @Override
    public int getCount() {
        return mList.size();
    }

    /**
     * 返回tag实例
     * @param context
     * @param position
     * @param parent
     * @return
     */
    @Override
    public View getView(Context context, int position, ViewGroup parent) {
        //初始化View
        View view = inflater.inflate(R.layout.layout_star_view_item, null);
        //初始化控件
        ImageView iv_star_icon = view.findViewById(R.id.iv_star_icon);
        TextView tv_star_name = view.findViewById(R.id.tv_star_name);
        tv_star_name.setText(mList.get(position));
        switch (position % 10){
            case 0:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_1);
                break;
            case 1:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_2);
                break;
            case 2:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_3);
                break;
            case 3:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_4);
                break;
            case 4:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_5);
                break;
            case 5:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_6);
                break;
            default:
                iv_star_icon.setImageResource(R.drawable.img_chat_bg_7);
                break;
        }
        return view;
    }

    /**
     * 返回tag数据
     * @param position
     * @return
     */
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    /**
     * 针对每个tag返回一个权重值
     * @param position
     * @return
     */
    @Override
    public int getPopularity(int position) {
        return 7;
    }

    /**
     * tag主题色发生变化时会回调该方法
     * @param view
     * @param themeColor
     */
    @Override
    public void onThemeColorChanged(View view, int themeColor) {

    }
}
